/* 
function makeIterator(arr) {
  let nextIndex = 0

  return {
    next: () => {
      if (nextIndex < arr.length) {
        return {
          value: arr[nextIndex++],
          done: false
        }
      } else {
        return {
          done: true
        }
      }
    }
  }
}

const it = makeIterator(['吃饭', '睡觉', '吃豆豆'])

console.log(it.next().value)
console.log(it.next().value)
console.log(it.next().value)
console.log(it.next().value) 
*/

function* makeIterator(arr) {
  for (let i of arr)
    yield i
}

const gen = makeIterator(['吃饭', '睡觉', '打豆豆'])

console.log(gen.next().value)
console.log(gen.next().value)
console.log(gen.next().value)
console.log(gen.next().done)